﻿using SqlScriptVault.Model;
using SqlScriptVault.Services;
using SqlScriptVault.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SqlScriptVault.View
{
    /// <summary>
    /// Interaction logic for LoginWindow.xaml
    /// </summary>
    public partial class LoginWindow : Window
    {
        public LoginWindow(Server server)
        {
            EventService.Instance.Subscribe(EventService.PasswordEvent, SupplyProvidedPassword);
            
            InitializeComponent();

            LoginViewModel viewModel = ((LoginViewModel)DataContext);

            viewModel.Server = server;
            viewModel.RequestClose += LoginWindow_RequestClose;

            viewModel.Initialize();
        }

        private object SupplyProvidedPassword(object arg)
        {
            //SecureString password = new SecureString();

            //foreach (char character in PasswordBox.Password)
            //{
            //    password.AppendChar(character);
            //}

            //return password;

            return PasswordBox.Password;
        }

        private void LoginWindow_RequestClose()
        {
            DialogResult = true;

            Close();
        }
    }
}
